package dao.impl;

import java.sql.SQLException;

import org.apache.commons.dbutils.handlers.BeanHandler;

import bean.Concern;
import dao.ConcernDao;


//Apply
public class ConcernDaoImpl extends BaseDao implements ConcernDao{

	@Override
	public Integer selectConcernbyid(Integer id) {
		try {
			Object query2=query.query("select * from concern where concernid=?",id,new BeanHandler<Concern>(Concern.class));
			return Integer.parseInt(query2.toString());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer deleteConcernbyid(Integer id) {
		try {
			return query.update("delete from concern where concernid=?",id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer updateConcern(Concern info) {
		String sql="update concern set userid=?,beconcerneduserid=? where concernid=?";
		try {
			return query.update(sql,info.getUserid(),info.getBeconcerneduserid());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer addConcern(Concern info) {
		String sql="insert into concern(userid,beconcerneduserid) VALUES(?,?)";
		try {
			return query.update(sql,info.getUserid(),info.getBeconcerneduserid());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

}
